package cn.tedu.goods.management.controller;


import cn.tedu.common.web.JsonResult;
import cn.tedu.goods.management.pojo.param.OrderRefundParam;
import cn.tedu.goods.management.service.IOrderRefundService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/orders/")
@Api(tags = "2. 退款管理")
public class OrderRefundController {
    @Autowired
    private IOrderRefundService orderRefundService;

    @ApiOperation("用户申请退款")
    @PostMapping("{orderId}/isRefund")
    public JsonResult refund(@Validated OrderRefundParam orderRefundParam){
        orderRefundService.refund(orderRefundParam);
        return JsonResult.ok();
    }

    @ApiOperation("同意退款")
    @PostMapping("{id}/refundY")
    public JsonResult refundY(@PathVariable Long id){
        orderRefundService.refundY(id);
        return JsonResult.ok();
    }

    @ApiOperation("拒绝退款")
    @PostMapping("{id}/refundN")
    public JsonResult refundN(@PathVariable Long id){
        orderRefundService.refundN(id);
        return JsonResult.ok();
    }

    @ApiOperation("获取退款列表")
    @GetMapping("list")
    public JsonResult list(){
        return JsonResult.ok(orderRefundService.list());
    }

}
